//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "LinearInterpolation.h"
using namespace Cephei::QL::Math::Interpolations;
#include <gen/QL/Math/Interpolation.h>
using namespace Cephei::QL::Math;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Interpolations::CLinearInterpolation::CLinearInterpolation (boost::shared_ptr<QuantLib::LinearInterpolation>& childNative, Object^ owner) : CInterpolation(CLinearInterpolation::typeid)
{
#ifdef HANDLE
	_phLinearInterpolation = NULL;
#endif
	_ppLinearInterpolation = &childNative;
    _ppInterpolation = new boost::shared_ptr<QuantLib::Interpolation> (boost::dynamic_pointer_cast<QuantLib::Interpolation> (*_ppLinearInterpolation));
}
Cephei::QL::Math::Interpolations::CLinearInterpolation::CLinearInterpolation (QuantLib::LinearInterpolation& childNative, Object^ owner) : CInterpolation(CLinearInterpolation::typeid)
{
#ifdef HANDLE
	_phLinearInterpolation = NULL;
#endif
	_ppLinearInterpolation = new boost::shared_ptr<QuantLib::LinearInterpolation> (&childNative);
    _ppInterpolation = new boost::shared_ptr<QuantLib::Interpolation> (boost::dynamic_pointer_cast<QuantLib::Interpolation> (*_ppLinearInterpolation));
    _LinearInterpolationOwner = owner;
    _InterpolationOwner = owner;
}

Cephei::QL::Math::Interpolations::CLinearInterpolation::CLinearInterpolation (CLinearInterpolation^ copy) : CInterpolation(CLinearInterpolation::typeid)
{
#ifdef HANDLE
	_phLinearInterpolation = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppLinearInterpolation = new boost::shared_ptr<QuantLib::LinearInterpolation> (copy->GetShared());
        _ppInterpolation = new boost::shared_ptr<QuantLib::Interpolation> (boost::dynamic_pointer_cast<QuantLib::Interpolation> (*_ppLinearInterpolation));
    }
}
Cephei::QL::Math::Interpolations::CLinearInterpolation::CLinearInterpolation (PLATFORM::Type^ t) : CInterpolation(CLinearInterpolation::typeid)
{
#ifdef HANDLE
	_phLinearInterpolation = NULL;
#endif
	if (!t->IsSubclassOf(CLinearInterpolation::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Interpolations::CLinearInterpolation::CLinearInterpolation (QuantLib::Handle<QuantLib::LinearInterpolation>& childNative, Object^ owner)  : CInterpolation(CLinearInterpolation::typeid)
{
	_phLinearInterpolation = &childNative;
	_ppLinearInterpolation = &static_cast<boost::shared_ptr<QuantLib::LinearInterpolation>>(childNative.currentLink());
    _ppInterpolation = new boost::shared_ptr<QuantLib::Interpolation> (boost::dynamic_pointer_cast<QuantLib::Interpolation> (*_ppLinearInterpolation));
    _LinearInterpolationOwner = owner;
}
Cephei::QL::Math::Interpolations::CLinearInterpolation::CLinearInterpolation (QuantLib::Handle<QuantLib::LinearInterpolation> childNative)  : CInterpolation(CLinearInterpolation::typeid)
{
	_phLinearInterpolation = &childNative;
	_ppLinearInterpolation = &static_cast<boost::shared_ptr<QuantLib::LinearInterpolation>>(childNative.currentLink());
    _ppInterpolation = new boost::shared_ptr<QuantLib::Interpolation> (boost::dynamic_pointer_cast<QuantLib::Interpolation> (*_ppLinearInterpolation));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Interpolations::CLinearInterpolation::CLinearInterpolation (QuantLib::LinearInterpolation childNative)  : CInterpolation(CLinearInterpolation::typeid)
{
#ifdef HANDLE
	_phLinearInterpolation = NULL;
#endif
	_ppLinearInterpolation = new boost::shared_ptr<QuantLib::LinearInterpolation> (new QuantLib::LinearInterpolation (childNative));
    _ppInterpolation = new boost::shared_ptr<QuantLib::Interpolation> (boost::dynamic_pointer_cast<QuantLib::Interpolation> (*_ppLinearInterpolation));
}
#endif

Cephei::QL::Math::Interpolations::CLinearInterpolation::~CLinearInterpolation ()
{
    if (_ppLinearInterpolation != NULL)
    {
	    delete _ppLinearInterpolation;
        _ppLinearInterpolation = NULL;
    }
}
Cephei::QL::Math::Interpolations::CLinearInterpolation::!CLinearInterpolation ()
{
    if (_ppLinearInterpolation != NULL)
    {
	    delete _ppLinearInterpolation;
    }
}
QuantLib::LinearInterpolation& Cephei::QL::Math::Interpolations::CLinearInterpolation::GetReference ()
{
    if (_ppLinearInterpolation == NULL) throw REFNEW NativeNullException ();
	return **_ppLinearInterpolation;
}
boost::shared_ptr<QuantLib::LinearInterpolation>& Cephei::QL::Math::Interpolations::CLinearInterpolation::GetShared ()
{
    if (_ppLinearInterpolation == NULL) throw REFNEW NativeNullException ();
	return *_ppLinearInterpolation;
}
QuantLib::LinearInterpolation* Cephei::QL::Math::Interpolations::CLinearInterpolation::GetPointer ()
{
    if (_ppLinearInterpolation == NULL) throw REFNEW NativeNullException ();
	return &**_ppLinearInterpolation;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::LinearInterpolation>& Cephei::QL::Math::Interpolations::CLinearInterpolation::GetHandle ()
{
	if (_phLinearInterpolation == NULL)
	{
		_phLinearInterpolation = new Handle<QuantLib::LinearInterpolation> (*_ppLinearInterpolation);
	}
	return *_phLinearInterpolation;
}
#endif
bool Cephei::QL::Math::Interpolations::CLinearInterpolation::HasNative () 
{
	return (_ppLinearInterpolation != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

